package org.suwenqian.audiovideosummary.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;
import org.suwenqian.audiovideosummary.dao.entity.ProgressLog;
import org.suwenqian.audiovideosummary.dao.mapper.ProgressLogMapper;
import org.suwenqian.audiovideosummary.service.ProgressLogService;

@Service
@RequiredArgsConstructor
public class ProgressLogServiceImpl extends ServiceImpl<ProgressLogMapper, ProgressLog> implements ProgressLogService {

    private final ProgressLogMapper progressLogMapper;

    private final SimpMessagingTemplate messagingTemplate;

    public void sendProgress(ProgressLog progressLog) {
        String destination = "/topic/progress/" + progressLog.getId();
        messagingTemplate.convertAndSend(destination, progressLog);
        // 推送后更新数据库
        progressLogMapper.insertOrUpdate(progressLog);
    }

}
